/**
 * Created by WT-SUN on 2017/4/18.
 */
$(function () {
    queryComboData();
    $.extend($.fn.validatebox.defaults.rules, {
        checkCode : {
            validator: function (value) {
                var checkR=$.ajax({
                    async : false,
                    cache : false,
                    type : 'post',
                    url : ROOT_PATH + '/occupationalHealth/occDiseases/selectByCode.shtml',
                    data : {
                        code:value
                    }
                }).responseText;
                var dataObj=$.parseJSON(checkR);//转换为json对象
                var flag=dataObj.success==true;
                if(!flag){
                    $('#code_err').css('display','block');
                }else {
                    $('#code_err').css('display','none');
                }
                return flag;
            },
            message: '当前标识已存在！'
        }
    });
});
function clearForm(){
    $('#disForm').form('reset');
}
/**
 * 提交表单
 */
function submitForm() {
    $('#disForm').form('submit', {
        url: ROOT_PATH + '/occupationalHealth/occDiseases/insertSelective.shtml',
        onSubmit: function (param) {
            if (!$(this).form('validate')) {
                layer.alert('请正确填写信息', {icon: 5});
            }
            return $(this).form('validate');
        },
        success: function (result) {
            result = $.parseJSON(result);
            if (result.success) {
                layer.msg('保存成功', {
                    icon: 1,
                    time: 1000
                }, function () {
                    var indexp = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(indexp); //再执行关闭
                    window.parent.reLoadData();
                });
            }
            else {
                layer.msg('保存失败', {
                    icon: 2,
                    time: 1000
                });
            }
        }
    });
}

function queryComboData() {
    var code=CONSTANT.DictionaryTypeDefConstants.OHE_OCCDISEASES_TYPE;
    $.ajax({
        type: 'post',
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',
        data: {code: code},
        dataType: "json",
        success: function (result) {
            $('#diseasesType').combobox({
                data: result,
                prompt:'请选择',
                valueField: 'id',
                textField: 'text',
                editable: false,
                panelHeight: '200'
            });
        }
    });
}
